﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _10_Panel_嵌入式窗体
{
    public partial class BaesForm : Form
    {


        public BaesForm()
        {
            InitializeComponent();
            //设置窗体的工作区域
            this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;//设置为屏幕的工作区域
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            this.pictureBox1.BackColor = Color.Red;
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.pictureBox1.BackColor = Color.SeaGreen;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Normal)
            {
                //当前窗体是正常状态，点击后最大化
                this.WindowState = FormWindowState.Maximized;
                this.pictureBox2.Image = Properties.Resources.最小化;
            }
            else
            {
                this.WindowState = FormWindowState.Normal;
                this.pictureBox2.Image = Properties.Resources.最大化;
            }
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }
        //用来记录鼠标点击的坐标
        int oldX;
        int oldY;

        /// <summary>
        /// 鼠标按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)//判断当前鼠标左键按下才进行响应
            {
                //记录下鼠标按下的位置
                oldX = e.Location.X;
                oldY = e.Location.Y;
            }

        }

        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button ==  MouseButtons.Left)
            {
                //获取原来按下的坐标位置，然后加上偏移
                this.Left += e.Location.X - oldX;
                this.Top += e.Location.Y - oldY;
            }
        }
    }
}
